package com.testdocker.demo.rest;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@RestController
public class Conn {

    @Autowired
    RedisTemplate redisTemplate;

    @RequestMapping("/")
    public String hello() {
        redisTemplate.opsForValue().set(String.valueOf(System.nanoTime()), "hi " + System.nanoTime());
        return "hello" + new Date();
    }

    @RequestMapping("/get")
    public String helloGet(HttpServletRequest request) {
        String k = request.getParameter("k");
        if (StringUtils.isEmpty(k)) {
            return "hello spring " + new Date();
        } else {
            return (String) redisTemplate.opsForValue().get(k);
        }
    }
}
